{% extends 'base.html' %}
{% block title %}
服务器管理页
{% endblock %}
{% block part1 %}
    <li class="active">
        <a class="dropdown-toggle" href="#">
            <i class="icon-group"></i>
            <span>主机管理</span>
            <i class="icon-chevron-down"></i>
        </a>
        <ul class="active submenu" style="display: block">
            <li><a href="/user/serverlist" class="active">主机管理</a></li>
            <li><a href="/user/servergroup">主机组</a></li>
        </ul>
    </li>
{% endblock %}
{% block content %}
<!-- main container -->
    <div class="content">

        <!-- settings changer -->
        <div class="skins-nav">
            <a href="#" class="skin first_nav selected">
                <span class="icon"></span><span class="text">Default</span>
            </a>
            <a href="#" class="skin second_nav" data-file="/static/css/skins/dark.css">
                <span class="icon"></span><span class="text">Dark skin</span>
            </a>
        </div>

        <div class="container-fluid">
            <div id="pad-wrapper">
                <!-- orders table -->
                <div class="table-wrapper orders-table section">
                    <div class="row-fluid head">
                        <div class="span12">
                            <h2>主机列表</h2>
                        </div>
                    </div>

                    <div class="row-fluid filter-block">
                        <div class="pull-right">
                            <div class="btn-group pull-right">
                                <button class="glow left large">搜索</button>
                                <button class="glow right large">
                                    <a href="/user/sregister">添加主机</a>
                                </button>
                            </div>
                            <input type="text" class="search order-search" placeholder="Search for an order.." />
                        </div>
                    </div>

                    <div class="row-fluid">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th class="span2">
                                        hostname
                                    </th>
                                    <th class="span3">
                                        ip
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        cpu
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        mem
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        disk
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        system
                                    </th>
                                    <th class="span3">
                                        <span class="line"></span>
                                        control
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <!-- row -->
                                {% for server in serverlist %}
                                <tr class="first">
                                    <td>
                                        <a href="/user/serverdetail/{{ server.id }}">{{ server.hostname }}</a>
                                    </td>
                                    <td>
                                        {{ server.ip }}
                                    </td>
                                    <td>
                                        {{ server.cpu }}
                                    </td>
                                    <td>
                                        {{ server.mem }}
                                    </td>
                                    <td>
                                        {{ server.disk }}
                                    </td>
                                    <td>
                                        {{ server.system }}
                                    </td>
                                    <td>
                                        <span class="label label-info">关联</span>
                                        <span class="label label-info" id="{{ server.id }}" onclick="del(this.id)">删除</span>
                                        <span class="label label-info">修改</span>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- end orders table -->
            </div>
        </div>
    </div>
    <!-- end main container -->
{% endblock %}
{% block jspart1 %}
    function del(id){
    if(confirm("确认删除") == false)
    {
        return;
    }
    $.ajax(
            {
                type:"post",
                url:"http://{{ request.get_host }}/user/delServer/",
                data:{'id': id},
                success:function(data){
                    if(data['status'] == 'success'){
                        window.location.reload()
                    }
                },
                error:function(err){
                    console.log(err)
                }
            }
    )
    }
{% endblock %}
